﻿@page "/OA_Manage/OA_DefForm/TreeList"

@inherits BaseList<OA_DefFormTree>

<Space Size="@("small")">
    <SpaceItem>
        <Button Type="@ButtonType.Primary" Icon="reload" OnClick="()=>Refresh()">刷新</Button>
    </SpaceItem>
</Space>


<Tree TItem="OA_DefFormTree"
      DataSource="Data"
      ChildrenExpression="node=>node.DataItem.Children"
      IsLeafExpression="node => !(node.DataItem.Children?.Count > 0)"
      TitleExpression="node=>node.DataItem.Text"
      KeyExpression="node=>node.DataItem.Id"
      DefaultExpandAll>
    <TitleTemplate>
        <Space>
            <Split>
                <Divider Type="DirectionVHType.Vertical" />
            </Split>
            <ChildContent>
                <SpaceItem>
                    @context.DataItem.Text
                </SpaceItem>
                @if (!string.IsNullOrEmpty(context.DataItem.jsonId))
                {
                    <SpaceItem>
                        <Button Type="@ButtonType.Link" Style="padding:0px" OnClick="()=>Edit(context.DataItem)">创建</Button>
                    </SpaceItem>
                    <SpaceItem>
                        <Button Type="@ButtonType.Link" Style="padding:0px" OnClick="()=>OpenEditor(context.DataItem)">查看流程图</Button>
                    </SpaceItem>
                }
            </ChildContent>
        </Space>
    </TitleTemplate>
</Tree>

@code {
    public TreeList()
    {
        Area = "OA_Manage";
        GetDataList = "GetTreeDataList";
    }

    protected override async void Edit(OA_DefFormTree para)
    {
        var modalConfig = new ModalOptions();
        modalConfig.Title = "发起流程";
        //modalConfig.Style = "top:20px;";
        // In order for Dispose in ConfirmTemplateDemo to take effect every time it is closed
        //modalConfig.BodyStyle += "overflow-y: auto;";
        modalConfig.DestroyOnClose = true;
        modalConfig.Centered = true;
        modalConfig.Width = 1200d;
        modalConfig.Footer = null;

        var modalRef = await ModalService.CreateModalAsync<OA_UserForm.EditForm, object>(modalConfig,
            new OA_UserFormDTO()
                {
                    Type = para.type,
                    DefFormId = para.key,
                    DefFormName = para.title,
                    JsonId = para.jsonId,
                    JsonVersion = para.jsonVersion,
                    WorkflowJSON = para.json,
                    ApplicantUserId = Operator?.UserId
                });

        modalRef.OnOk = () =>
        {
            return Task.CompletedTask;
        };
    }

    protected async void OpenEditor(OA_DefFormTree para)
    {
        var modalConfig = new ModalOptions();
        modalConfig.Title = "查看流程";
        //modalConfig.Style = "top:20px;";
        // In order for Dispose in ConfirmTemplateDemo to take effect every time it is closed
        //modalConfig.BodyStyle += "overflow-y: auto;";
        modalConfig.DestroyOnClose = true;
        modalConfig.Centered = true;
        modalConfig.Width = 1200d;
        modalConfig.Footer = null;

        var modalRef = await ModalService.CreateModalAsync<TreeEditForm, object>(modalConfig, para?.json);

        modalRef.OnOk = () =>
        {
            return Task.CompletedTask;
        };
    }
}
